<?php

namespace app\controller;

use app\model\GpsInfoModel;
use think\worker\Server;
use Workerman\Lib\Timer;

class RealTimeAllWorkerSocket extends Server
{
    protected $socket = 'websocket://0.0.0.0:25897';

    public function onConnect($connection)
    {
        //3秒运行一次
        Timer::add(3, function () use ($connection) {
            $info = GpsInfoModel::getAllInfoLocation();
            $connection->send(json_encode($info));
        });

    }
}

